package handler

import (
	"net/http"

	"frame/internal/app/user/httputils/user/dto/request"
	"frame/internal/app/user/httputils/user/dto/response"
	"frame/internal/app/user/service"
	"github.com/gin-gonic/gin"
)

// UserController 控制器结构，持有 UserService
type UserController struct {
	userService *service.UserService
}

// NewUserController 创建新的 UserController
func NewUserController(userService *service.UserService) *UserController {
	return &UserController{userService: userService}
}
func UserHandler(c *gin.Context, req request.VerifyRequest) {

	c.JSON(200, response.VerifyResponse{Success: true, Message: "success"})
	return

}

// CreateUser 处理用户创建请求
func (uc *UserController) CreateUser(c *gin.Context) {
	var req request.CreateUser

	// 调用服务层创建用户
	user, err := uc.userService.CreateUser(req.ID, req.Name, req.Email, req.Street, req.City, req.State, req.Country)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}

	// 返回成功响应
	c.JSON(http.StatusOK, gin.H{
		"id":      user.ID,
		"name":    user.Name,
		"email":   user.Email.GetValue(),
		"address": user.Address.GetValue(),
	})
}
